package com.zhupanlin.zhyl.hosp.controller.api;

import com.zhupanlin.zhyl.common.result.Result;
import com.zhupanlin.zhyl.hosp.service.DepartmentService;
import com.zhupanlin.zhyl.hosp.service.HospitalService;
import com.zhupanlin.zhyl.hosp.service.HospitalSetService;
import com.zhupanlin.zhyl.hosp.service.ScheduleService;
import com.zhupanlin.zhyl.model.hosp.Hospital;
import com.zhupanlin.zhyl.model.hosp.Schedule;
import com.zhupanlin.zhyl.model.vo.hosp.DepartmentVo;
import com.zhupanlin.zhyl.model.vo.hosp.HospitalQueryVo;
import com.zhupanlin.zhyl.vo.hosp.ScheduleOrderVo;
import com.zhupanlin.zhyl.vo.order.SignInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/11/30 17:06
 */
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private HospitalSetService hospitalSetService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    // findHospList/
    @ApiOperation("查询医院列表")
    @GetMapping("findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable("page") Integer page,
                               @PathVariable("limit") Integer limit,
                               HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitals = hospitalService.seleceHospPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitals);
    }

    @ApiOperation("根据医院名称查询")
    @GetMapping("findByHosname/{hosname}")
    public Result findByHosName(@PathVariable("hosname") String hosname) {
        List<Hospital> list = hospitalService.findByHosname(hosname);
        return Result.ok(list);
    }

    @ApiOperation("根据医院编号获取科室信息")
    @GetMapping("department/{hoscode}")
    public Result index(@PathVariable("hoscode") String hoscode) {
        List<DepartmentVo> list = departmentService.findDeptTree(hoscode);
        return Result.ok(list);
    }

    @ApiOperation("根据医院编号获取医院预约挂号详情")
    @GetMapping("findHospDetail/{hoscode}")
    public Result item(@PathVariable("hoscode") String hoscode) {
        Map<String, Object> map = hospitalService.item(hoscode);
        return Result.ok(map);
    }

    // 获取可预约的排班数据
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingScheduleRule(@PathVariable("page") Long page,
                                         @PathVariable("limit") Long limit,
                                         @PathVariable("hoscode") String hoscode,
                                         @PathVariable("depcode") String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    // 获取排班数据
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList( @PathVariable("hoscode") String hoscode,
                                    @PathVariable("depcode") String depcode,
                                    @PathVariable("workDate") String workDate) {
        return Result.ok(scheduleService.getScheduleDetail(hoscode, depcode, workDate));
    }

    // 根据排班 id 获取排班数据
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable("scheduleId") String scheduleId) {
        Schedule schedule = scheduleService.getSucheduleById(scheduleId);
        return Result.ok(schedule);
    }

    // 根据排班 id 获取预约下单数据
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    // 获取医院签名信息
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }

}
